package com.api.shopapi.controller;

import com.alibaba.fastjson.JSONObject;
import com.api.shopapi.entity.*;
import com.api.shopapi.service.InstitutionStaffRelService;
import com.api.shopapi.service.NursingSchedulingChangeRecordService;
import com.api.shopapi.service.StaffService;
import com.api.shopapi.util.Util;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author maochuan
 */
@RestController
@RequestMapping("NursingSchedulingChangeRecord")
public class NursingSchedulingChangeRecordController extends BaseController {

    @Autowired
    @Qualifier("NursingSchedulingChangeRecordServiceImplOne")
    private NursingSchedulingChangeRecordService nursingSchedulingChangeRecordService;

    @Autowired
    @Qualifier("StaffServiceImplOne")
    private StaffService staffService;


    @Autowired
    @Qualifier("InstitutionStaffRelServiceImplOne")
    private InstitutionStaffRelService institutionStaffRelService;



    @RequestMapping(value = "Page", method = RequestMethod.POST)
    public MyResult getList(@RequestBody JSONObject jsonObject) {
        try {
            String timeStr = jsonObject.getString("timeStr");
            String sign = jsonObject.getString("sign");
            String staffCode = jsonObject.getString("staffCode");
            String startTime = jsonObject.getString("startTime");
            String endTime = jsonObject.getString("endTime");
            int pageIndex = jsonObject.getInteger("pageIndex");
            int pageSize = jsonObject.getInteger("pageSize");
            PreCheck preCheck = checkSignAdmInterface(timeStr, sign, staffCode,"/NursingSchedulingChangeRecord/Page");
            if (preCheck.getError() == 1) {
                return failed(preCheck.getMessage());
            }
            InstitutionStaffRel institutionStaffRel = institutionStaffRelService.getByStaffCode(staffCode);
            String institutionCode = institutionStaffRel.getInstitutionCode();

            endTime = Util.timeAddDay(endTime,1);
            PageInfo<NursingSchedulingChangeRecord> nursingSchedulingChangeRecordPageInfo = nursingSchedulingChangeRecordService.getPageList(pageIndex, pageSize,institutionCode, startTime, endTime);

            return success(nursingSchedulingChangeRecordPageInfo);
        } catch (Exception e) {
            insertError("/NursingSchedulingChangeRecord/Page", jsonObject.toJSONString(), getExceptionMsg(e), "api");
            return anomalous(getExceptionMsg(e));
        }

    }

}
